package com.only4play.authcenter.infrastructure.convert;


import com.only4play.authcenter.constants.ApplicationType;
import com.only4play.authcenter.constants.AuthType;
import com.only4play.authcenter.constants.ResourceType;
import com.only4play.authcenter.constants.ThirdPartyAuthType;

import java.util.Objects;

/**
 * @author hinzzz www.hinzzz.cn 157957329@qq.com
 * 2024-02-27
 */
public class CustomMapper {

    public ApplicationType int2ApplicationType(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return ApplicationType.of(code).orElse(null);
    }

    public Integer applicationType2Int(ApplicationType applicationType) {
        return applicationType.getCode();
    }


    public AuthType int2AuthType(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return AuthType.of(code).orElse(null);
    }

    public Integer authType2Int(AuthType authType) {
        return authType.getCode();
    }

    public ResourceType int2ResourceType(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return ResourceType.of(code).orElse(null);
    }

    public Integer resourceType2Int(ResourceType resourceType) {
        return resourceType.getCode();
    }

    public ThirdPartyAuthType int2ThirdPartyAuthType(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return ThirdPartyAuthType.of(code).orElse(null);
    }

    public Integer thirdPartyAuthType2Int(ThirdPartyAuthType thirdPartyAuthType) {
        return thirdPartyAuthType.getCode();
    }


}
